//
//  CardTypeView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/11.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class CardTypeView: UIView {

    fileprivate let titleLabel = UILabel()
    let moreButton = UIButton()
    let arrowImageView = UIButton()
    
    var text : String! {
        didSet{
            titleLabel.text = text
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: .zero)
        
        self.backgroundColor = UIColor.white
        
        let titleImageView = UIImageView()
        titleImageView.image = UIImage.imageWithName("gift_box")
        self.addSubview(titleImageView)
        
        titleLabel.textColor = UIColor.red
        titleLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 18))
        self.addSubview(titleLabel)
        
        moreButton.setTitle(more_title, for: .normal)
        moreButton.setTitleColor(UIColor.lightGray, for: .normal)
        moreButton.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        self.addSubview(moreButton)
        
        arrowImageView.layer.contents = #imageLiteral(resourceName: "double_arrow_right").cgImage
        self.addSubview(arrowImageView)
        
        let grayView = UIView()
        grayView.backgroundColor = UIColor.lineColor()
        self.addSubview(grayView)
        
        titleImageView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 8))
            make.centerY.equalToSuperview()
            make.width.height.equalTo(RATIO_H(maxNum: 30))
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleImageView.snp.right).offset(RATIO(maxNum: 8))
            make.centerY.equalTo(titleImageView)
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
        
        arrowImageView.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(RATIO(maxNum: -8))
            make.centerY.equalToSuperview()
            make.width.height.equalTo(RATIO_H(maxNum: 20))
        }
        
        moreButton.snp.makeConstraints { (make) in
            make.right.equalTo(arrowImageView.snp.left).offset(RATIO(maxNum: -2))
            make.centerY.equalTo(arrowImageView)
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
        
        grayView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
